#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "disurl.h"

static void N(int S, int P, int Q, int * K, int * H)
{
	int R;
	for (R=S; R<=P; R++)
	{
		K[R] = R + Q;
		H[R+Q] = R;
	}
}

static void A(const char * Q, char * S, int * K, int * H, int M)
{
	int P, R, U;
	
	P = strlen(Q);
	
	for (R=0; R<P; R++)
	{
		int T = Q[R];
		if ((T >= 'A' && T <= 'Z')
			|| (T >= 'a' && T <= 'z')
			|| (T >= '0' && T <= '9'))
		{
			U = H[Q[R]] - M;
			if (U < 0)
			{
				U += 62;
			}
			T = K[U];
		}
		sprintf(S, "%s%c", S, T);
	}
}

void disurl(char * urlbuf, const char * F, const char * I)
{
	//var F=1224070425,L=0;
	//var I="0CC8://v4Du.916zwt7FB.v75/D8/5DB1v/0DtG16.F5t",J="0CC8://v4Du.916zwt7FB.v75/D8/5DB1v/0DtG16.F5t";
	int K[256]={0},H[256]={0};
	int M;
	//var B=G("urln"),C=G("urla");
	int Fv = atoi(F);
	
	urlbuf[0] = 0;
	N(0,9,48,K,H);
	N(10,35,55,K,H);
	N(36,61,61,K,H);
	
	M = Fv % 26;
	M = M?M:1;
	
	A(I, urlbuf, K, H, M);
}


